package com.woniuxy.controller;

import com.woniuxy.entity.Invoice_register;
import com.woniuxy.entity.OrderEntity;
import com.woniuxy.entity.QueryEntity;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.InvoiceRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Leimin
 * @date 2022/04/26 19:09
 **/
@RestController
@RequestMapping("/invoice")
@Api(tags = "发票接口")
public class InvioceRegisterController {
    @Autowired
    InvoiceRegisterService invoiceRegisterService;

    @PostMapping("/condition")
    @ApiOperation(value = "条件查询发票分页数据")
    public ResponseEntity findAllByPage(@ApiParam(name = "queryEntity", value="查询条件") @RequestBody QueryEntity<Invoice_register> queryEntity){

        return invoiceRegisterService.findAllByCondition(queryEntity);
    }

    @GetMapping("/invoice")
    @ApiOperation(value = "获取所有发票数据")
    public ResponseEntity findAll(){

        return invoiceRegisterService.findAll();
    }

    @GetMapping("/invoice/{id}")
    @ApiOperation(value = "获取一个发票数据")
    public ResponseEntity findOne(@ApiParam(name = "id", value="发票id") @PathVariable int id){

        return invoiceRegisterService.findOne(id);
    }

    @PostMapping("/invoice")
    @ApiOperation(value = "新增发票")
    public ResponseEntity addOne(@ApiParam(name = "invoice_register", value="新增的发票") @RequestBody Invoice_register invoice_register){

        return invoiceRegisterService.addOne(invoice_register);
    }

    @DeleteMapping("/invoice/{id}")
    @ApiOperation(value = "删除发票")
    public ResponseEntity deleteOne(@ApiParam(name = "id", value="发票id") @PathVariable int id){

        return invoiceRegisterService.deleteOne(id);
    }

    @PutMapping("/invoice/batchDel")
    @ApiOperation(value = "批量删除发票")
    public ResponseEntity deleteBatch(@ApiParam(name = "ids", value="发票id数组")@RequestBody int[] ids){

        return invoiceRegisterService.deleteBatch(ids);
    }

    @PutMapping("/invoice")
    @ApiOperation(value = "更新发票")
    public ResponseEntity updateOne(@ApiParam(name = "invoice_register", value="更新的发票") @RequestBody Invoice_register invoice_register){

        return invoiceRegisterService.updateOne(invoice_register);
    }

    @PostMapping("/showOrder")
    @ApiOperation(value = "获取未支付的订单")
    public ResponseEntity showOrder(@ApiParam(name = "queryEntity", value="查询条件") @RequestBody QueryEntity<OrderEntity> queryEntity){

        return invoiceRegisterService.findOrder(queryEntity);
    }
}

